home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Tools & Goodies / IntlTest / Sources / View.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  4.2 KB  |  189 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                View.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Mary Boetcher
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "IntlTest.hpp"
  13.  
  14. #ifndef VIEW_H
  15. #include "View.h"
  16. #endif
  17.  
  18. #ifndef DEFINES_K
  19. #include "Defines.k"
  20. #endif
  21.  
  22. #ifndef FRAME_H
  23. #include "Frame.h"
  24. #endif
  25.  
  26. #ifndef PART_H
  27. #include "Part.h"
  28. #endif
  29.  
  30. // ----- Framework Layer -----
  31.  
  32. #ifndef FWUTIL_H
  33. #include "FWUtil.h"
  34. #endif
  35.  
  36. #ifndef FWFRAME_H
  37. #include "FWFrame.h"
  38. #endif
  39.  
  40. #ifndef FWCONTXT_H
  41. #include "FWContxt.h"
  42. #endif
  43.  
  44. #ifndef FWEDVIEW_H
  45. #include "FWEdView.h"
  46. #endif
  47.  
  48. // ----- OS Layer -----
  49.  
  50. #ifndef FWMENU_H
  51. #include "FWMenu.h"
  52. #endif
  53.  
  54. #ifndef FWEVENT_H
  55. #include "FWEvent.h"
  56. #endif
  57.  
  58. #ifndef FWODGEOM_H
  59. #include "FWODGeom.h"
  60. #endif
  61.  
  62. #ifndef FWRECT_H
  63. #include "FWRect.h"
  64. #endif
  65.  
  66. #ifndef FWRECSHP_H
  67. #include "FWRecShp.h"
  68. #endif
  69.  
  70. #ifndef FWTXTSHP_H
  71. #include "FWTxtShp.h"
  72. #endif
  73.  
  74. #ifndef FWPICSHP_H
  75. #include "FWPicShp.h"        
  76. #endif
  77.  
  78. #ifndef FWALERT_H
  79. #include "FWAlert.h"            
  80. #endif
  81.  
  82. // ----- OpenDoc Includes -----
  83.  
  84. #ifndef SOM_Module_OpenDoc_Commands_defined
  85. #include <CmdDefs.xh>
  86. #endif
  87.  
  88. #ifndef SOM_Module_OpenDoc_StdProps_defined
  89. #include <StdProps.xh>
  90. #endif
  91.  
  92. #ifndef SOM_ODSession_xh
  93. #include <ODSessn.xh>
  94. #endif
  95.  
  96. #ifndef SOM_ODDispatcher_xh
  97. #include <Disptch.xh>
  98. #endif
  99.  
  100. //========================================================================================
  101. // RunTime Info
  102. //========================================================================================
  103.  
  104. #ifdef FW_BUILD_MAC
  105. #pragma segment odfIntlTest
  106. #endif
  107.  
  108. //========================================================================================
  109. // CIntlTestView
  110. //========================================================================================
  111.  
  112. FW_DEFINE_CLASS_M1(CIntlTestView, FW_CSuperView);
  113.  
  114. //----------------------------------------------------------------------------------------
  115. // CIntlTestView::CIntlTestView
  116. //----------------------------------------------------------------------------------------
  117.  
  118. CIntlTestView::CIntlTestView(Environment* ev, FW_CSuperView* container, 
  119.                              const FW_CRect& contentRect, const FW_CPoint& extent)
  120. :    FW_CSuperView(ev, container, contentRect, 0, extent, FW_kNoScrolling)
  121. {
  122.     // Adjust the bounds but don't redraw now
  123.     CenterInFrame(ev, contentRect.Size(), false);
  124. }
  125.  
  126. //----------------------------------------------------------------------------------------
  127. // CIntlTestView::~CIntlTestView
  128. //----------------------------------------------------------------------------------------
  129.  
  130. CIntlTestView::~CIntlTestView()
  131. {
  132. }
  133.  
  134. //----------------------------------------------------------------------------------------
  135. // CIntlTestView::Draw
  136. //----------------------------------------------------------------------------------------
  137.  
  138. void CIntlTestView::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  139. {
  140.     // Set up drawing context for this view
  141.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  142.  
  143.     // Erase with white first 
  144.     FW_CRect invalidRect;
  145.     vc.GetClipRect(invalidRect);
  146.     FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. // CIntlTestView::CenterInFrame
  151. //----------------------------------------------------------------------------------------
  152.  
  153. void CIntlTestView::CenterInFrame(Environment* ev, FW_CPoint& contentSize, FW_Boolean redraw)
  154. {
  155.     FW_CPoint    viewSize(GetSize(ev));
  156.     FW_CPoint    viewExtent(GetExtent(ev));
  157.     FW_CPoint    viewLoc;
  158.  
  159.     // Center the content view if it's smaller, or align it if it's bigger
  160.     if (viewSize != contentSize) 
  161.     {    
  162.         if (contentSize.x > viewExtent.x) 
  163.         {
  164.             viewLoc.x = FW_Half(contentSize.x - viewExtent.x);
  165.             viewSize.x = viewExtent.x;
  166.         }
  167.         else 
  168.         { 
  169.             viewLoc.x = FW_kFixed0;
  170.             viewSize.x = contentSize.x;
  171.         }
  172.         
  173.         if (contentSize.y > viewExtent.y) 
  174.         {
  175.             viewLoc.y = FW_Half(contentSize.y - viewExtent.y);
  176.             viewSize.y = viewExtent.y;
  177.         }
  178.         else 
  179.         {
  180.             viewLoc.y = FW_kFixed0;
  181.             viewSize.y = contentSize.y;
  182.         }
  183.         
  184.         SetLocation(ev, viewLoc, redraw);
  185.         SetSize(ev, viewSize, redraw);
  186.     }    
  187. }
  188.  
  189.